﻿using System;
using System.Runtime.InteropServices;
using System.IO;
using System.Reflection;

namespace MLogix
{
   sealed public unsafe class Win32
    {
        static public string location = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
        internal const int HWND_BROADCAST = 0xffff;
        internal const int WM_WININICHANGE = 0x001A;
        [DllImport("coredll.dll")]
        internal static extern int SendMessage(IntPtr hWnd, uint msg, int wParam, int lParam);
        [DllImport("coredll.dll")]
        internal static extern int RegFlushKey(IntPtr hKey);
        [DllImport("coredll.dll")]
        public static extern IntPtr SetCursor(IntPtr hCursor);
        [DllImport("SMSStore.dll")]
        public static extern bool createSMSinStore(string toNumber, string message, string displayName, SYSTEMTIME messageTime, bool fromMe);
        [StructLayout(LayoutKind.Sequential)]
        public unsafe struct SYSTEMTIME
        {
            [MarshalAs(UnmanagedType.U2)]
            private short Year;
            [MarshalAs(UnmanagedType.U2)]
            private short Month;
            [MarshalAs(UnmanagedType.U2)]
            private short DayOfWeek;
            [MarshalAs(UnmanagedType.U2)]
            private short Day;
            [MarshalAs(UnmanagedType.U2)]
            private short Hour;
            [MarshalAs(UnmanagedType.U2)]
            private short Minute;
            [MarshalAs(UnmanagedType.U2)]
            private short Second;
            [MarshalAs(UnmanagedType.U2)]
            private short Milliseconds;

            public SYSTEMTIME(DateTime dt)
            {
                //dt = dt.ToUniversalTime();  // SetSystemTime expects the SYSTEMTIME in UTC
                Year = (short)dt.Year;
                Month = (short)dt.Month;
                DayOfWeek = (short)dt.DayOfWeek;
                Day = (short)dt.Day;
                Hour = (short)dt.Hour;
                Minute = (short)dt.Minute;
                Second = (short)dt.Second;
                Milliseconds = (short)dt.Millisecond;
            }
        }

    }
}
